import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import createAutoImport from './plugins/auto-import'
import createUnPluginComponents from './plugins/unplugin-components'
import createSetupExtend from './plugins/setup-extend'
import createCompression from './plugins/compression'
import createSvgIconsPlugin from './plugins/svg-icons'
import createViteImages from './plugins/vue-images'
import createVisualizer from './plugins/rollup-visualizer'
import createProgress from './plugins/progress'
// import createLegacy from './plugins/legacy'
// import htmlPlugin from './plugins/html-plugin'
import pwa from './plugins/pwa'

export default function createVitePlugins(viteEnv, isBuild = false) {
  const vitePlugins = [vue({ reactivityTransform: true }), vueJsx()]
  vitePlugins.push(createAutoImport())
  vitePlugins.push(createUnPluginComponents())
  vitePlugins.push(createSetupExtend())
  vitePlugins.push(createSvgIconsPlugin())
  vitePlugins.push(createViteImages())

  vitePlugins.push(pwa())

  // vitePlugins.push(htmlPlugin(getHtmlPluginData(viteEnv, isBuild)))
  if (isBuild) {
    vitePlugins.push(...createCompression(viteEnv))
    // vitePlugins.push(createLegacy())
    vitePlugins.push(createVisualizer())
  } else {
    vitePlugins.push(createProgress())
  }
  return vitePlugins
}

// function getHtmlPluginData(viteEnv, isBuild) {
//   //luckysheet xlsx 插件判断
//   const jqPlugin = isBuild
//     ? '<script src="./resource/luckysheet/plugin.js" ></script>'
//     : '<script src="https://cdn.jsdelivr.net/npm/luckysheet/dist/plugins/js/plugin.js" async defer></script>'
//   const luckysheet = isBuild
//     ? '<script src="./resource/luckysheet/luckysheet.umd.js" ></script>'
//     : '<script src="https://cdn.jsdelivr.net/npm/luckysheet/dist/luckysheet.umd.js"  async defer></script>'
//   return { title: viteEnv.VITE_APP_TITLE, jqPlugin, luckysheet }
// }
